<?php
	@session_start();
	include("../../connect/connect_mysql.php");
	
function redirect($path){
    header("Location: $path");
}  
function check_file_type($filename){
	$upload_type = array('jpg', 'jpeg', 'gif', 'png', 'bmp');
    $start	= strrpos($filename, ".");
	if ( $start < strlen($filename) ){
		$user_type	= strtolower(substr($filename, $start+1));
		if ( in_array($user_type, $upload_type) ){
			return true;
		}
	}
	return false;
}

	if ($_FILES['uploadlogo']['name']!= "" && check_file_type($_FILES['uploadlogo']['name'])){
		$tempFile = $_FILES['uploadlogo']['tmp_name'];
		$targetPath = $_SERVER['DOCUMENT_ROOT'] .'/wheelhouse/upload/logo/';
		$targetFile =  str_replace('//','/',$targetPath) . $_FILES['uploadlogo']['name'];
		// Uncomment the following line if you want to make the directory if it doesn't exist
		// mkdir(str_replace('//','/',$targetPath), 0755, true);
		move_uploaded_file($tempFile,$targetFile);
	$path="upload/logo/".$_FILES['uploadlogo']['name'];
	$page= $_POST["group"];
	$location= $_POST["location"];
	$date= $_POST["date"] ;	
	$query = "SELECT * FROM page WHERE name = '$page'";
	$rs= mysql_query($query);
	
	if($rs){
		while ($row = mysql_fetch_array($rs, MYSQL_NUM)) {
			$id =$row[0];
		}
	}
	mysql_query ("SET NAMES 'utf8'");
	mysql_query("INSERT INTO `logo` (`page_id`, `date`,`location`, `path`,`flag`,`is_deleted`) VALUES ('$id','$date','$location','$path','0','0');");
		redirect('/wheelhouse/admin/?act=add_logo&flag=1');
	}
	else{
		redirect('/wheelhouse/admin/?act=add_logo&flag=0');
	}
?>
